package org.chameleon.limit.manager;

import org.chameleon.datasource.manager.AbsJzConfigManager;
import org.chameleon.limit.convert.JsonLimitConvert;
import org.chameleon.limit.entity.RateLimiterConfig;


/**
 * Apollo配置管理中心，负责读取&更新对应的配置
 */
public class JzLimitConfigManger extends AbsJzConfigManager<RateLimiterConfig> {

    private static final String CACHE_PREFIX = "JzLimitConfigManger:";


    public JzLimitConfigManger(String appNameLimit) {
        super(appNameLimit, new JsonLimitConvert());
    }

    @Override
    public String buildCacheKey(RateLimiterConfig rateLimiterConfig) {
        return CACHE_PREFIX + rateLimiterConfig.getGroup() + ":" + rateLimiterConfig.getKey();
    }

    @Override
    public String getGroup(RateLimiterConfig config) {
        return config.getGroup();
    }

    @Override
    public String getKey(RateLimiterConfig config) {
        return config.getKey();
    }
}
